package com.ch3;

import com.ch4.User;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelHandler.Sharable;

@Sharable
public class EchoServerHandler2 extends ChannelInboundHandlerAdapter {

	
	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
			throws Exception {
	  
		cause.printStackTrace();
		ctx.close();
		
		
	}
	 
	 
	@Override
	public void channelRead(ChannelHandlerContext ctx, Object msg)
			throws Exception {
		// TODO Auto-generated method stub
		//User infoString=(User)msg;
		
		System.out.println(">>>>>"+(String)msg);
		ByteBuf echo = Unpooled.copiedBuffer((msg+"good,$$").getBytes());
		ctx.writeAndFlush(echo);
	}
//	
//	@Override
//	public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
//		// TODO Auto-generated method stub
//	    ctx.flush();
//	    System.out.println(">>>>>>>>>>>>>>READ COMPLETED");
//	}
//	 
	 
}
